﻿<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ViewModel="clr-namespace:StoryQ.Converter.Wpf.ViewModel"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    xmlns:Converters="clr-namespace:StoryQ.Converter.Wpf.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    x:Class="StoryQ.Converter.Wpf.Window1"
    Title="StoryQ Converter"
    Height="600"
    Width="820"
    MinHeight="400"
    MinWidth="640"
    Closed="Window_Closed" mc:Ignorable="d">
    <Window.Resources>
        <Converters:ConverterChain x:Key="ib2v">
            <Converters:InvertConverter/>
            <BooleanToVisibilityConverter/>
        </Converters:ConverterChain>
        <Converters:StringFormatConverter x:Key="flagFinder" Format="Images/Flags/{0}.gif" />

        <ViewModel:Converter x:Key="vm" TransitionApplied="FocusLastChar" d:IsDataSource="true"/>
        <ObjectDataProvider MethodName="GetValues"
                        ObjectType="{x:Type System:Enum}"
                        x:Key="TestFrameworkValues">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="ViewModel:TestFramework" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <Converters:EnumToDoubleConverter x:Key="e2d"/>
        <Converters:UnCamelConverter x:Key="uc"/>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="FontFamily" Value="Consolas"/>
            <Setter Property="TextWrapping" Value="NoWrap"/>
            <Setter Property="AutoWordSelection" Value="True"/>
            <Setter Property="AcceptsReturn" Value="True"/>
            <Setter Property="AcceptsTab" Value="True"/>
            <Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="HorizontalScrollBarVisibility" Value="Auto"/>
        </Style>
        <DataTemplate x:Key="flags">
            <ItemsControl ItemsSource="{Binding}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Image RenderOptions.BitmapScalingMode="NearestNeighbor" Source="{Binding Converter={StaticResource flagFinder}}" Stretch="None" Margin="1,0,0,0" />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </DataTemplate>
    </Window.Resources>
    <DockPanel DataContext="{StaticResource vm}">
        <DockPanel.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFCFCFD0" Offset="1"/>
                <GradientStop Color="#FFE1E2E4"/>
                <GradientStop Color="#FFF4F4F4" Offset="0.142"/>
                <GradientStop Color="#FFF2F3F4" Offset="0.732"/>
            </LinearGradientBrush>
        </DockPanel.Background>




        <Border DockPanel.Dock="Top" Margin="5,5,5,1" Background="#FFF8F8F8" BorderBrush="#FFCED1D4" BorderThickness="1" CornerRadius="3">
            <DockPanel Height="28">
                <StackPanel x:Name="left" Orientation="Horizontal" DataContext="{Binding Settings}">
                    <TextBlock Margin="8,0,5,0" VerticalAlignment="Center" FontSize="12" FontWeight="Bold" Text="Output Settings"/>
                    <Rectangle Fill="#FFD0D0D1" StrokeThickness="0" Margin="5" Width="1" Stroke="#FF7E7E7E"/>
                    <CheckBox Content="Special Indentation" IsChecked="{Binding SpecialIndentation}" VerticalAlignment="Center" Margin="5,0" ToolTip="Use normal C# indentation, or Story-like indentation" />
                    <ComboBox  Margin="5,0" Width="75" VerticalAlignment="Center" ItemsSource="{Binding Source={StaticResource TestFrameworkValues}}" SelectedValue="{Binding TargetTestFramework}" ToolTip="The target test framework"/>
                    <Slider Margin="5,0" VerticalAlignment="Center" Width="80" Minimum="1" Maximum="4" Value="{Binding Level, Converter={StaticResource e2d}}" x:Name="slider" TickFrequency="1" TickPlacement="None" IsSnapToTickEnabled="True" ToolTip="The level of code to generate" />
                    <TextBlock  Margin="5,0" Text="{Binding Level, Converter={StaticResource uc}}" VerticalAlignment="Center"/>
                </StackPanel>
                <StackPanel x:Name="right" Orientation="Horizontal" d:LayoutOverrides="Height" DockPanel.Dock="Right">
                    <ComboBox Width="130" Margin="5,0" ItemsSource="{Binding LanguagePacks}" SelectedItem="{Binding CurrentLanguagePack}" IsReadOnly="True" VerticalAlignment="Center">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <Grid Width="105" Height="18" >
                            		<ProgressBar x:Name="progressBar" Value="{Binding DownloadProgress}" Visibility="{Binding IsDownloaded, Converter={StaticResource ib2v}}" Opacity="0.5" Maximum="1" Minimum="0" Background="#FFE2C359" Margin="0,1" ToolTip="This language pack is not yet downloaded" BorderBrush="{x:Null}" BorderThickness="0" />
                            		<TextBlock Text="{Binding Text, Mode=OneWay}" VerticalAlignment="Center" Margin="4,0,0,0"/>
                            		<ContentControl  HorizontalAlignment="Right" ContentTemplate="{StaticResource flags}" Content="{Binding CountryCodes}" MaxWidth="40" VerticalAlignment="Center" Margin="0,0,2,0">
                            			<ContentControl.OpacityMask>
                            				<LinearGradientBrush EndPoint="40,0" MappingMode="Absolute">
                            					<GradientStop Color="White" Offset="0.65"/>
                            					<GradientStop Offset="1"/>
                            				</LinearGradientBrush>
                            			</ContentControl.OpacityMask>
                            			<ContentControl.ToolTip>
                            				<ContentControl Padding="5" ContentTemplate="{StaticResource flags}" Content="{Binding CountryCodes}" />
                            			</ContentControl.ToolTip>
                            		</ContentControl>
                            	</Grid>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                    <Button Command="{Binding SaveLibrariesCommand}" ToolTip="Exports the StoryQ library files to a specified directory. Use this when you want to reference StoryQ in your own test projects." HorizontalAlignment="Center" Margin="5,0,2,0" VerticalAlignment="Center">
                        <DockPanel Margin="2,1,5,1">
                            <Image Source="Images\save.gif" Stretch="None" VerticalAlignment="Center" Margin="0,0,4,0"/>
                            <TextBlock Text="Export lib" VerticalAlignment="Center" />
                        </DockPanel>
                    </Button>
                </StackPanel>
                <Grid x:Name="space" Width="100"/>
            </DockPanel>
        </Border>



        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="1*"/>
            </Grid.ColumnDefinitions>
            <DockPanel Margin="7,7,5,7">
                <ItemsControl DockPanel.Dock="Bottom" ItemsSource="{Binding Transitions}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Button Margin="5" Command="{Binding Apply}" Content="{Binding Text}" ToolTip="{Binding Description}"/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <TextBox x:Name="src" Text="{Binding PlainText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
            </DockPanel>
            <TextBox IsReadOnly="true" Grid.Column="1" Text="{Binding ConvertedText}" Margin="5,7,7,7"/>
        </Grid>
    </DockPanel>
</Window>
